﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataEntity;
using JScripter;
using BusinessLogic.Controller;
using BusinessLogic;

public partial class Admin_AjaxPages_PropertyProsessionAdd : AjaxPage
{
    private int ID
    {
        get
        {
            if (Request.Params["ppid"] != null || AjaxState.ContainsKey("ppid"))
            {
                if (!AjaxState.ContainsKey("ppid"))
                    AjaxState["ppid"] = Request.Params["ppid"];
                return Convert.ToInt32(AjaxState["ppid"]);
            }
            else
            {
                return 0;
            }
        }
    }


    private void AddData()
    {
        try
        {
            PropertyProsession objPropertyProsession = new PropertyProsession();

            
            objPropertyProsession.Name = HtmlHelper.ControlValue(txtName.ClientID);

            objPropertyProsession.ModifiedDate = DateTime.Now;

            new PropertyProsessionController().Add(objPropertyProsession);
            Response.Redirect("~/Admin/AjaxPages/PropertyProsessionList.aspx");
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = "<div class='error'>" + ex.Message + "</div>";
        }
    }

    private void EditData()
    {

        PropertyProsession objPropertyProsession = new PropertyProsession();

        objPropertyProsession.PropertyProsessionID = ID;

        objPropertyProsession.Name = HtmlHelper.ControlValue(txtName.ClientID);

        objPropertyProsession.ModifiedDate = DateTime.Now;

        new PropertyProsessionController().UpdateByPropertyProsessionID(objPropertyProsession);
        Response.Redirect("~/Admin/AjaxPages/PropertyProsessionList.aspx");
    }

    private void BindData()
    {
        var dataBunch = new PropertyProsessionController().GetbyPropertyProsessionID(ID);
        if (dataBunch.Count > 0)
        {
            var data = dataBunch[0];

         
            txtName.Text = data.Name;

         
        }
    }

    protected void AddAjaxClick(object sender, AjaxControl.AjaxEventArg e)
    {
        AddData();

    }
    protected void UpdateAjaxClick(object sender, AjaxControl.AjaxEventArg e)
    {
        EditData();
    }
    public void PreventData()
    {
        txtName.Text = HtmlHelper.ControlValue(txtName.ClientID);
       
    }

}